package loan.calc.exception;

public class GlobalUncheckedException extends RuntimeException implements BaseException{

    private final Integer code;

    private final String message;

    @Override
    public Integer getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return message;
    }

    public GlobalUncheckedException(Integer code, String message) {
        super(message);
        this.code = code;
        this.message = message;
    }

    public GlobalUncheckedException(Integer code, String format, Object... args) {
        super(String.format(format,args));
        this.code = code;
        this.message = String.format(format, args);
    }

    public static GlobalUncheckedException instance(ExceptionEnum exceptionEnum, String format, Object... args) {
        return exceptionEnum == null
                ? new GlobalUncheckedException(ExceptionEnum.SYS_ERR.getCode(), format, args)
                : new GlobalUncheckedException(exceptionEnum.getCode(), format, args);
    }
}
